package com.guo.loadinganim;

import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.transition.ChangeBounds;
import androidx.transition.Scene;
import androidx.transition.Transition;
import androidx.transition.TransitionInflater;
import androidx.transition.TransitionManager;

public class ViewTransitionManager {
    private TransitionManager mTransitionManager = new TransitionManager();
    private static final String TAG = "ViewTransitionManager";

    public ViewTransitionManager() {
    }

    public void setScene(int destId, ViewGroup parent){
        Scene sceneDst = Scene.getSceneForLayout(parent, destId, parent.getContext());
        ChangeBounds bounds = new ChangeBounds();
        TransitionManager.go(sceneDst, bounds);
        bounds.setDuration(500);

        bounds.addListener(new Transition.TransitionListener() {
            @Override
            public void onTransitionStart(@NonNull Transition transition) {

            }

            @Override
            public void onTransitionEnd(@NonNull Transition transition) {
                Log.d(TAG, "transition end");
            }

            @Override
            public void onTransitionCancel(@NonNull Transition transition) {

            }

            @Override
            public void onTransitionPause(@NonNull Transition transition) {

            }

            @Override
            public void onTransitionResume(@NonNull Transition transition) {

            }
        });
    }

}
